package it.danghongphat.gui.component;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;

public class ContractTree extends JPanel
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public JTree tree;
	/**
	 * Constructs a tree with the contact persons in the different countries.
	 *
	 */
	public DefaultMutableTreeNode belgiumNode;
	public DefaultMutableTreeNode	dangnhapNode;
	public ContractTree()
	{
		
		// Create the nodes of the countries and their contact person nodes.
				DefaultMutableTreeNode nodeHangHoa = new DefaultMutableTreeNode("Hàng Hóa");
				nodeHangHoa.add(new DefaultMutableTreeNode(""));
				nodeHangHoa.add(new DefaultMutableTreeNode("Danh mục hàng hóa"));
				
				DefaultMutableTreeNode nodeNguoidung = new DefaultMutableTreeNode("Người Dùng");
//				nodeNguoidung.setI
				nodeNguoidung.add(new DefaultMutableTreeNode("Thông tin người dùng"));
				nodeNguoidung.add(new DefaultMutableTreeNode("Đổi mật khẩu"));
				DefaultMutableTreeNode addUser = new DefaultMutableTreeNode("++");
				nodeNguoidung.add(addUser);
				
				DefaultMutableTreeNode nodeKhachhang = new DefaultMutableTreeNode("Khách Hàng");
				nodeKhachhang.add(new DefaultMutableTreeNode("Danh sách khách hàng"));
				nodeKhachhang.add(new DefaultMutableTreeNode("Thông tin khách hàng"));
				
				DefaultMutableTreeNode nodeNghiepvu = new DefaultMutableTreeNode("Nghiệp Vụ");
				nodeNghiepvu.add(new DefaultMutableTreeNode("Thông tin đầu kỳ"));
				nodeNghiepvu.add(new DefaultMutableTreeNode("Nhập hàng"));
				nodeNghiepvu.add(new DefaultMutableTreeNode("Xuất hàng"));
				nodeNghiepvu.add(new DefaultMutableTreeNode("Tồn cuối"));
				
				// Create the root and add the country nodes.
				DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Quản lý");
				rootNode.add(nodeNguoidung);
				rootNode.add(nodeKhachhang);
				rootNode.add(nodeHangHoa);
				rootNode.add(nodeNghiepvu);
				
				// Create the tree model.
				TreeModel treeModel = new DefaultTreeModel(rootNode);
				
				tree = new JTree(treeModel);
				//----------------------------------------------------------------
				tree.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent mc) {
						super.mouseClicked(mc);
					}
					
				});
				
				//----------------------------------------------------------------
				tree.setRootVisible(false);
				// Expand the tree.
				for (int row = 0; row < tree.getRowCount(); row++)
				{
					tree.expandRow(row);
				}
				
				// Add the tree in a scroll pane.
				this.setLayout(new BorderLayout());
				JScrollPane jscroll = new JScrollPane(tree);
				this.add(jscroll, BorderLayout.CENTER);
				
				jscroll.setPreferredSize(new  Dimension(150, 300));
				tree.setPreferredSize(new  Dimension(150, 300));
				this.setPreferredSize(new Dimension(150, 300));
				
		}	
	}

